class_name PlayerStateBicycleKick
extends PlayerState


const BALL_HEIGHT_MIN : float =6
const BALL_HEIGHT_MAX : float=40
const BUNUS_POWER := 1.5

func _enter_tree() -> void:
	animation_player.play("bicycle_kick")
	ball_detection_area.body_entered.connect(on_ball_entered.bind())


func on_ball_entered(contract_ball:Ball)->void:
	if contract_ball.can_air_connect(BALL_HEIGHT_MIN,BALL_HEIGHT_MAX):
		var destination := target_goal.get_random_target_postition()
		var direction := ball.position.direction_to(destination)
		contract_ball.shoot(direction*player.power*BUNUS_POWER)
		SoundPlayer.play(SoundPlayer.Sound.POWERSHOT)




func on_animation_complete() -> void:
	transition_state(Player.State.RECOVERING)
